package com.zbu.test;

import java.util.Arrays;

/**
 * 冒泡排序：相邻两个元素作比较，大的元素向后移，依次即可
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] arr = {55,23,98,14,33,56};
        int temp;
        System.out.println(Arrays.toString(arr));
        for (int i = 0; i < arr.length-1; i++) {
            for (int j = 0; j < arr.length-i-1; j++) {
                if (arr[j] > arr[j+1]){
                    temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }
            }

        }
        System.out.println(Arrays.toString(arr));

    }

}
